import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';

/**
 * 订单信息
 */
@Entity('order_order')
export class OrderOrderEntity extends BaseEntity {
  @Column({ comment: '用户ID', nullable: true })
  userId: number;

  @Index({ unique: true })
  @Column({ comment: '订单号', length: 50 })
  orderNo: string;

  @Column({
    comment: '支付状态',
    dict: ['待支付', '已支付', '支付失败', '已退款'],
    default: 0,
  })
  payStatus: number;

  @Column({
    comment: '物流状态',
    dict: ['待发货', '已发货', '运输中', '已签收', '退货中', '已退货'],
    default: 0,
  })
  deliveryStatus: number;

  @Column({
    comment: '支付方式',
    dict: ['微信支付', '支付宝', '银行卡', '其他'],
    default: 0,
  })
  payType: number;

  @Column({ comment: '微信支付码', nullable: true })
  wechatPayCode: string;

  @Column({ comment: '支付截图', nullable: true })
  payScreenshot: string;

  @Column({ comment: '总金额', type: 'decimal', precision: 10, scale: 2 })
  totalAmount: number;

  @Column({ comment: '优惠金额', type: 'decimal', precision: 10, scale: 2, default: 0 })
  discountAmount: number;

  @Column({ comment: '支付金额', type: 'decimal', precision: 10, scale: 2, default: 0 })
  payAmount: number;

  @Column({ comment: '备注', nullable: true, type: 'text' })
  remark: string;

  @Column({ comment: '商品IDS', default: '' })
  GoodIds: string;

  @Column({ 
    comment: '商品详情', 
    type: 'json', 
    nullable: true 
  })
  productDetails: Array<{
    id: number;
    name: string;
    price: number;
    type: number;
  }>;

  @Column({ 
    comment: '优惠详情', 
    type: 'json', 
    nullable: true 
  })
  discountDetails: Array<{}>;

  @Column({ comment: '下单时间', type: 'datetime', nullable: true })
  orderTime: Date;

  @Column({ comment: '支付时间', type: 'datetime', nullable: true })
  payTime: Date;

  @Column({ comment: '收货地址', nullable: true })
  address: string;

  @Column({ comment: '收货人', nullable: true, length: 50 })
  consignee: string;

  @Column({ comment: '联系电话', nullable: true, length: 20 })
  phone: string;

  @Column({ comment: '支付截图', nullable: true })
  payImg: string;

  @Column({ comment: '验光单', nullable: true })
  eyeglassImg: string;

  // 添加微信支付相关字段
  @Column({ comment: '微信支付商户号', nullable: true, length: 32 })
  mchId: string;

  @Column({ comment: '微信支付订单号', nullable: true, length: 32 })
  transactionId: string;

  @Column({ comment: '微信支付预支付ID', nullable: true, length: 64 })
  prepayId: string;

  @Column({ comment: '微信支付二维码链接', nullable: true })
  codeUrl: string;

  @Column({ comment: '微信支付H5链接', nullable: true })
  h5Url: string;

  @Column({ comment: '微信支付小程序支付参数', type: 'json', nullable: true })
  miniPayParams: {
    appId: string;
    timeStamp: string;
    nonceStr: string;
    package: string;
    signType: string;
    paySign: string;
  };

  @Column({ comment: '支付失败原因', nullable: true })
  failReason: string;

  @Column({ comment: '退款金额', type: 'decimal', precision: 10, scale: 2, default: 0 })
  refundAmount: number;

  @Column({ comment: '退款时间', type: 'datetime', nullable: true })
  refundTime: Date;

  @Column({ comment: '退款单号', nullable: true, length: 32 })
  refundNo: string;

  @Column({ comment: '店铺ID', default: 0 })
  shopId: number;

  @Column({ comment: '销售ID', default: 0 })
  adminId: number;

  // 中天订单号
  @Column({ comment: '中天订单号', nullable: true, length: 32 })
  zhongtianOrderNo: string;

  // 中天下单时间
  @Column({ comment: '中天下单时间', nullable: true, type: 'datetime' })
  zhongtianOrderTime: Date;

  // 中天物流号
  @Column({ comment: '中天物流号', nullable: true, length: 32 })
  zhongtianLogisticsNo: string; 

  // 验光数据
  @Column({ comment: '验光数据', nullable: true, type: 'json' })
  optometricsData: string

  // 中天下单请求数据
  @Column({ comment: '中天下单请求数据', nullable: true, type: 'json' })
  zhongtianOrderRequestData: string

  // 瞳康订单号
  @Column({ comment: '瞳康订单号', nullable: true, length: 32 })
  tongkangOrderNo: string;

  // 门店下单时间
  @Column({ comment: '门店下单时间', nullable: true, type: 'datetime' })
  shopOrderTime: Date;

  // 瞳康下单时间
  @Column({ comment: '瞳康下单时间', nullable: true, type: 'datetime' })
  tongkangOrderTime: Date;

  // 瞳康下单请求数据
  @Column({ comment: '瞳康下单请求数据', nullable: true, type: 'json' })
  tongkangOrderRequestData: string

  // 瞳康下单返回数据
  @Column({ comment: '瞳康下单返回数据', nullable: true, type: 'json' })
  tongkangOrderResponseData: string

  // 订单进度
  @Column({ comment: '订单下单进度', default: 0 })
  orderProgress: number;

  // 分账订单ID
  @Column({ comment: '分账订单ID', default:0 })
  shareOrderId: number;

  // 逻辑删除
  @Column({ comment: '逻辑删除', default: false })
  isDeleted: boolean;

  // 订单类型
  @Column({ comment: '订单类型', nullable: true })
  orderType: String;

  // 镜片代号
  @Column({ comment: '镜片代号', nullable: true })
  lensCode: String;

  // 镜片数量 （0为双眼，1为左眼，2为右眼）
  @Column({ comment: '镜片数量', default: 0 })
  lensQuantity: number;
}
